
Imports System.Data
Imports System.Data.SqlClient


Namespace Producto
Public Class Marca

public Function Listar(MarcaId as integer) as Entity.Producto.Marca

Dim strNameProcedure as string = "up_Pro_Marca_obtener"
Dim sqlReader As SqlDataReader = Nothing
Dim sqlCon As SqlConnection = New SqlConnection(Configuracion.Connexion.Cnn)
dim objEnt as   entity.Producto.Marca
Try
            sqlCon.Open()
Dim sqlCmd As SqlCommand = New SqlCommand(strNameProcedure, sqlCon)
With sqlCmd
.CommandType = CommandType.StoredProcedure
                .Parameters.Add(New SqlParameter("@MarcaId", SqlDbType.Int)).Value =MarcaId
            End With
            sqlReader = sqlCmd.ExecuteReader(CommandBehavior.CloseConnection)
If sqlReader.HasRows Then
While sqlReader.Read
 objEnt= new    entity.Producto.Marca
With objEnt
		.MarcaId = sqlReader("MarcaId").ToString
		.Nombre = sqlReader("Nombre").ToString
		.Descripcion = sqlReader("Descripcion").ToString
		.Catalogo = sqlReader("Catalogo").ToString
End With
  End While
  End IF
 Catch ex As Exception
Throw New Exception(ex.ToString)
Finally
 sqlReader.Dispose()
  sqlReader.Close()
  sqlReader = Nothing
  sqlCon.Dispose()
 sqlCon.Close()
 sqlCon = Nothing
 End Try
return objEnt

End Function


'***************************



public Function Listar(Opcion as string , _
		MarcaId as Integer, _
		Nombre as String, _
		Descripcion as String, _
		Catalogo as Integer) _
as  Entity.Producto.MarcaCol

Dim strNameProcedure as string = "up_Pro_Marca_listar"
dim objCol as   entity.Producto.MarcaCol
Try
Using conn As New SqlConnection(Configuracion.Connexion.Cnn)
Dim cmd As New SqlCommand(strNameProcedure, conn)
cmd.CommandType = CommandType.StoredProcedure
  cmd.Parameters.Add(New SqlParameter("@opcion", SqlDbType.varchar,50)).Value =Opcion
 cmd.Parameters.Add(New SqlParameter("@MarcaId",SqlDbType.INT)).Value =MarcaId
 cmd.Parameters.Add(New SqlParameter("@Nombre",SqlDbType.VARCHAR,100)).Value =Nombre
 cmd.Parameters.Add(New SqlParameter("@Descripcion",SqlDbType.VARCHAR,50)).Value =Descripcion
 cmd.Parameters.Add(New SqlParameter("@Catalogo",SqlDbType.SMALLINT)).Value =Catalogo
conn.Open()
Using dr As SqlDataReader = cmd.ExecuteReader()
		dim iMarcaId as integer = dr.GetOrdinal("MarcaId")
		dim iNombre as integer = dr.GetOrdinal("Nombre")
		dim iDescripcion as integer = dr.GetOrdinal("Descripcion")
		dim iCatalogo as integer = dr.GetOrdinal("Catalogo")
		dim i_usu_cre as integer = dr.GetOrdinal("_usu_cre")
		dim i_fec_cre as integer = dr.GetOrdinal("_fec_cre")
		dim i_usu_mod as integer = dr.GetOrdinal("_usu_mod")
		dim i_Fec_mod as integer = dr.GetOrdinal("_Fec_mod")
		dim i_flg_Eli as integer = dr.GetOrdinal("_flg_Eli")

 Dim colCount As Integer = dr.FieldCount
 Dim values As Object() = New Object(colCount - 1) {}

 objCol =  New entity.Producto.MarcaCol
  If dr.HasRows Then
While dr.Read()
dim objEnt =  new entity.Producto.Marca
dr.GetValues(values)

		objEnt.MarcaId = values(iMarcaId)
		objEnt.Nombre = values(iNombre)
		objEnt.Descripcion = values(iDescripcion)
		objEnt.Catalogo = values(iCatalogo)
 objCol.Add(objEnt)
 End While
 End if
 End Using
 End Using
 Catch ex As Exception
Throw New Exception(ex.ToString)
Finally
 End Try
return objCol

End Function


'***************************


Public  Function Insert(ByVal opcion As String, _
		MarcaId as Integer, _
		Nombre as String, _
		Descripcion as String, _
		Catalogo as Integer, _
vUsuario as integer ) As Integer

 dim strNameProcedure as string ="Up_Pro_Marca_Insertar"
 Try
Dim intCodigo As Integer = -1
 Using sqlCon As SqlConnection = New SqlConnection(Configuracion.Connexion.Cnn)
Using sqlCmd As SqlCommand = New SqlCommand(strNameProcedure, sqlCon)
With sqlCmd
 .CommandType = CommandType.StoredProcedure
 .Parameters.Add(New SqlParameter("@opcion", SqlDbType.VarChar, 120)).Value = opcion
 .Parameters.Add(New SqlParameter("@MarcaId",SqlDbType.INT)).Value =MarcaId
 .Parameters.Add(New SqlParameter("@Nombre",SqlDbType.VARCHAR,100)).Value =Nombre
 .Parameters.Add(New SqlParameter("@Descripcion",SqlDbType.VARCHAR,50)).Value =Descripcion
 .Parameters.Add(New SqlParameter("@Catalogo",SqlDbType.SMALLINT)).Value =Catalogo
 .Parameters.Add(New SqlParameter("@_usuario", SqlDbType.Int)).Value = vUsuario
 .Parameters.Add(New SqlParameter("@_fecha", SqlDbType.BigInt)).Value = now.tofiletime()
.Parameters.Add(New SqlParameter("@variable_out", SqlDbType.Int))
 .Parameters("@variable_out").Direction = ParameterDirection.Output
 sqlCon.Open()
 .ExecuteNonQuery()
 intCodigo = .Parameters("@variable_out").Value
  Return intCodigo
  End With
 End Using
 End Using
 Catch ex As Exception
  Throw New Exception(ex.Message)
 Return -1
 End Try

End Function


'***************************


Public  Function Update(ByVal opcion As String, _
		MarcaId as Integer, _
		Nombre as String, _
		Descripcion as String, _
		Catalogo as Integer, _
vUsuario as integer ) As Integer

 dim strNameProcedure as string ="Up_Pro_Marca_Actualizar"
 Try
Dim intCodigo As Integer = -1
 Using sqlCon As SqlConnection = New SqlConnection(Configuracion.Connexion.Cnn)
Using sqlCmd As SqlCommand = New SqlCommand(strNameProcedure, sqlCon)
With sqlCmd
 .CommandType = CommandType.StoredProcedure
 .Parameters.Add(New SqlParameter("@opcion", SqlDbType.VarChar, 120)).Value = opcion
 .Parameters.Add(New SqlParameter("@MarcaId",SqlDbType.INT)).Value =MarcaId
 .Parameters.Add(New SqlParameter("@Nombre",SqlDbType.VARCHAR,100)).Value =Nombre
 .Parameters.Add(New SqlParameter("@Descripcion",SqlDbType.VARCHAR,50)).Value =Descripcion
 .Parameters.Add(New SqlParameter("@Catalogo",SqlDbType.SMALLINT)).Value =Catalogo
 .Parameters.Add(New SqlParameter("@_usuario", SqlDbType.Int)).Value = vUsuario
 .Parameters.Add(New SqlParameter("@_fecha", SqlDbType.BigInt)).Value = now.tofiletime()
.Parameters.Add(New SqlParameter("@variable_out", SqlDbType.Int))
 .Parameters("@variable_out").Direction = ParameterDirection.Output
 sqlCon.Open()
 .ExecuteNonQuery()
 intCodigo = .Parameters("@variable_out").Value
  Return intCodigo
  End With
 End Using
 End Using
 Catch ex As Exception
  Throw New Exception(ex.Message)
 Return -1
 End Try

End Function


'***************************


Public Shared Function Eliminar(ByVal opcion As String, MarcaId as integer, vusuario as integer) as integer

 dim strNameProcedure as string ="Up_Pro_Marca_Eliminar"
 Try
Dim intCodigo As Integer = -1
 Using sqlCon As SqlConnection = New SqlConnection(Configuracion.Connexion.Cnn)
Using sqlCmd As SqlCommand = New SqlCommand(strNameProcedure, sqlCon)
With sqlCmd
 .CommandType = CommandType.StoredProcedure
 .Parameters.Add(New SqlParameter("@opcion", SqlDbType.VarChar, 120)).Value = opcion
                .Parameters.Add(New SqlParameter("@MarcaId", SqlDbType.Int)).Value =MarcaId
 .Parameters.Add(New SqlParameter("@_usuario", SqlDbType.Int)).Value = vUsuario
 .Parameters.Add(New SqlParameter("@_fecha", SqlDbType.BigInt)).Value = now.tofiletime()
.Parameters.Add(New SqlParameter("@variable_out", SqlDbType.Int))
 .Parameters("@variable_out").Direction = ParameterDirection.Output
 sqlCon.Open()
 .ExecuteNonQuery()
 intCodigo = .Parameters("@variable_out").Value
  Return intCodigo
  End With
 End Using
 End Using
 Catch ex As Exception
  Throw New Exception(ex.Message)
 Return -1
 End Try

End Function


'***************************



End Class



end namespace

